package com.zachary.es;

import com.alibaba.fastjson.JSON;
import com.zachary.es.dtd.Medicine;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.RecordWriter;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.util.Progressable;
import org.elasticsearch.hadoop.mr.EsOutputFormat;

import java.io.IOException;
import java.util.Date;

/**
 * <pre>
 * Created with IntelliJ IDEA.
 * User: zachary.
 * Date: 2014/7/15
 * Time: 17:29
 * PC：windows'IDEA in company <br>
 * </pre>
 *
 * @author zachary.
 */
public class App {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration conf = HBaseConfiguration.create();
        conf.set("es.nodes", "192.168.1.109");
        conf.set("es.port", "9200");
        conf.set("es.input.json", "yes");
        conf.set("es.resource", "post/basic");

        Job job = Job.getInstance(conf);
        job.setJobName("esIndex");


        EsOutputFormat esOutputFormat = new EsOutputFormat();
        RecordWriter recordWriter = esOutputFormat.getRecordWriter(null, new JobConf(conf), null, new Progressable() {
            @Override
            public void progress() {

            }        });
        recordWriter.write(null, JSON.toJSONString(new Medicine(777777, "世界杯",new Date(), 44444.1,null)));


    }
}
